<template>
    <div class="sidebar_box">
        <div class="logo">
            <div class="logo_img">
                <!-- <img src="../../assets/img/slogan.png" alt=""> -->
            </div>
        </div>
        <el-menu class="sidebar-el-menu sidebar" :default-active="onRoutes" background-color="#001529"
            text-color="#ffffffa6" active-text-color="#fff" :default-openeds="openeds"  router>
            <template v-for="item in navList">
                <template v-if="item.children">
                    <el-submenu :index="item.name">
                        <template slot="title">
                            <i :class="item.icon"></i>
                            <span slot="title" style="height: 40px;line-height: 40px;">{{ item.name }}</span>
                        </template>
                        <template v-for="subItem in item.children">
                            <template>
                                <el-menu-item :index="subItem.path" :key="subItem.path">{{ subItem.name }}
                                </el-menu-item>
                            </template>
                        </template>
                    </el-submenu>
                </template>
                <template v-else>
                    <el-menu-item :index="item.path" :key="item.path">
                        <i :class="item.icon"></i>
                        <span slot="title">{{ item.name }}</span>
                    </el-menu-item>
                </template>
            </template>
        </el-menu>
    </div>
</template>

<script>
import bus from '../common/bus';
export default {
    data() {
        return {
            openeds: [''],
            collapse: false,
         
            navList: [
                // // {path:'home',name:'首页',icon:'el-icon-s-home',},
                // {
                //     path:'',
                //     name:'站点',
                //     icon:'el-icon-menu',
                //     children:[
                //         {path:'home',name:'站点列表'},

                //     ]
                // },
                // {
                //     path:'',
                //     name:'系统管理',
                //     icon:'el-icon-s-tools',
                //     children:[
                //         {path:'user',name:'用户列表'},

                //     ]
                // },
                
               
            ],
            menu: [],
            active: 0,
        };
    },
    computed: {

        onRoutes() {
            return this.$route.path.replace('/', '');
           
        }
    },
    created() {
        const role = localStorage.getItem('ms_menu');
        this.navList = JSON.parse(localStorage.getItem("ms_menu"));
        // console.log(this.navList)
        // if (this.navList[this.active]["children"] == undefined) {
        //     this.menu = [];
        // } else {
        //     this.menu = this.navList[this.active]["children"];
        // }
        // 通过 Event Bus 进行组件间通信，来折叠侧边栏
        bus.$on('collapse', msg => {
            this.collapse = msg;
            bus.$emit('collapse-content', msg);
        });
    },
    methods: {
        handleOpen(key, keyPath) {
            // console.log(key, keyPath);
        },
        handleClose(key, keyPath) {
            // console.log(key, keyPath);
        }
    }
};
</script>

<style scoped>
.sidebar_box{
    background: #001529;
    width: 200px;
}
.sidebar {
    display: block;
    position: absolute;
    left: 0;
    top: 70px;
    bottom: 0;
    overflow-y: scroll;
    /* padding-top: 100px; */
    background: #001529;
}
.logo{
    height: 70px;
    text-align: center;
    line-height: 70px;
    display: flex;
}
.logo_img{
    width: 60px;
    height: 54px;
    margin: auto;
}
.logo_img img{
    width: 100%;
    height: 100%;
}

.sidebar::-webkit-scrollbar {
    width: 0;
}

.sidebar-el-menu:not(.el-menu--collapse) {
    width: 200px;
}
:deep(.el-submenu__title){
    height: 40px !important;
    line-height: 40px !important;
}
.el-submenu__title i {
    color: #fff !important;
    font-size: 14px;
}

.sidebar>ul {
    height: 100%;
}

.el-menu-item {
    height: 40px;
    line-height: 40px;
}
.el-submenu .el-menu{
    background: #000c17 !important;
}
.el-menu-item.is-active {
    background: #1890ff !important;
}
.el-menu-item.is-active i{
    color: #fff !important;
}

.el-menu-item i,
.el-submenu__title i {
    color: #fff;
    font-size: 16px;
}

.el-menu-item.is-active i {
    color: #333;
}
.el-menu-item:focus, .el-menu-item:hover{
    color: #fff !important;
}

</style>
